{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Restoring parameters from /tmp/model.ckpt\n",
      "Test Accuracy: 0.97333336\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      setosa       1.00      1.00      1.00        50\n",
      "  versicolor       1.00      0.92      0.96        50\n",
      "   virginica       0.93      1.00      0.96        50\n",
      "\n",
      "   micro avg       0.97      0.97      0.97       150\n",
      "   macro avg       0.98      0.97      0.97       150\n",
      "weighted avg       0.98      0.97      0.97       150\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import print_function\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "from sklearn.datasets import load_iris\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import classification_report\n",
    "\n",
    "# note: this has to be imported in case to support forest graph\n",
    "from tensorflow.contrib.tensor_forest.python import tensor_forest\n",
    "\n",
    "import os\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n",
    "\n",
    "saver = tf.train.import_meta_graph('/tmp/model.ckpt.meta')\n",
    "\n",
    "data = load_iris()\n",
    "\n",
    "dX, dy = data[\"data\"], data[\"target\"]\n",
    "\n",
    "graph = tf.get_default_graph()\n",
    "with tf.Session() as sess:\n",
    "    new_saver = tf.train.import_meta_graph('/tmp/model.ckpt.meta')\n",
    "    new_saver.restore(sess, '/tmp/model.ckpt')\n",
    "    #input = graph.get_operation_by_name(\"train\")\n",
    "    # print(graph.as_graph_def())\n",
    "    load_infer_op = graph.get_tensor_by_name('probabilities:0')\n",
    "    accuracy_op = graph.get_tensor_by_name('Mean_1:0')\n",
    "    X = graph.get_tensor_by_name('Placeholder:0')\n",
    "    Y = graph.get_tensor_by_name('Placeholder_1:0')\n",
    "    print(\"Test Accuracy:\", sess.run(accuracy_op, feed_dict={X: dX, Y: dy}))\n",
    "    result = sess.run(load_infer_op, feed_dict={X: dX})\n",
    "    prediction_result = [i.argmax() for i in result]\n",
    "    print(classification_report(dy, prediction_result,\n",
    "                                target_names=data[\"target_names\"]))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
